﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Npu_Platform
{
    public partial class ConnectForm : Form
    {
        public Client client;
        delegate void SetTextCallback(String Text);
        delegate void MessageBoxCallback(Exception Ex);

        public ConnectForm()
        {
            InitializeComponent();
        }
        public ConnectForm(Client c)
        {
            InitializeComponent();
            this.client = c;
            client.SendMessage += new Client.SendMessageEventHandler(DisplayMessage);
            client.SendError += new Client.SendErrorEventHandler(DisplayError);
        }
      
        private void button_Cancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void ConnectForm_Shown(object sender, EventArgs e)
        {
            client.SendError += new Client.SendErrorEventHandler(DisplayError);
            client.ClientInit();
            progressBar1.Value = 10;
            client.ClientConnect();
            
        }
        public void DisplayError(Exception ex)
        {
            ConnectForm.MessageBoxCallback d = new ConnectForm.MessageBoxCallback(ShowError);
            this.Invoke(d, new object[] { ex });
        }
        public void DisplayMessage(String s)
        {
            ConnectForm.SetTextCallback d = new ConnectForm.SetTextCallback(ShowMessage);
            this.Invoke(d, new object[] { s });
        }
        public void ShowError(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

        public void ShowMessage(String s)
        {
            //MessageText.Text += s + "\r\n";
        }

    }
}
